package com.egg.ylt.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.egg.ylt.R;
import com.egg.ylt.Utils.Constants;
import com.egg.ylt.Utils.CustomUtils;
import com.egg.ylt.Utils.StatusBarUtil;
import com.egg.ylt.Utils.StringUtil;
import com.egg.ylt.pojo.BindEquipmentEntity;
import com.egg.ylt.presenter.impl.ScanCodePresenterImpl;
import com.egg.ylt.view.IScanCodeView;
import com.yonyou.framework.library.base.BaseActivity;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.utils.AppSharedPreferences;
import com.yonyou.framework.library.common.utils.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ACT_InputFacilityNumber extends BaseActivity<ScanCodePresenterImpl> implements IScanCodeView {

    @BindView(R.id.include_rl_view)
    RelativeLayout mIncludeRlView;

    @BindView(R.id.include_iv_back)
    ImageView includeIvBack;
    @BindView(R.id.include_tv_title)
    TextView includeTvTitle;
    @BindView(R.id.edit_facility_number)
    EditText editFacilityNumber;
    @BindView(R.id.btn_link_facility)
    TextView btnLinkFacility;
    @BindView(R.id.ll_load_view)
    LinearLayout llLoadView;

    private AppSharedPreferences mSp;

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_input_facility_number;
    }

    @Override
    protected View getLoadingTargetView() {
        return llLoadView;
    }

    @Override
    protected void initViewsAndEvents() {

        StatusBarUtil.setStatusBarColor(this, R.color.ylt_whit);
        StatusBarUtil.StatusBarLightMode(this);
        CustomUtils.setImmersiveStatusBar(mContext, mIncludeRlView);
        
        mSp = new AppSharedPreferences(mContext);
        //初始化控件
        includeTvTitle.setText("输入设备号");

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    public void showBusinessError(ErrorBean error) {

    }


    @Override
    public void setBindFacility(BindEquipmentEntity entity) {
        if (entity == null) {
            return;
        }
        ToastUtil.makeText(mContext, "添加成功", false);
        mSp.putString(Constants.BABY_ID, entity.getBabyId());
        mSp.putString(Constants.SWIM_RING_ID, entity.getCode());
        readyGo(ACT_HomePage.class);
    }

    @Override
    public void getScanFailure() {
//        finish();
    }

    @OnClick({R.id.include_iv_back, R.id.btn_link_facility})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.include_iv_back://返回键
                finish();
                break;
            case R.id.btn_link_facility://绑定设备
                String mCode = editFacilityNumber.getText().toString().trim();
                if (StringUtil.isEmpty(mCode)) {
                    ToastUtil.makeText(mContext, "请输入设备号", false);
                    return;
                }
                mPresenter.setBind(Constants.TOKEN, "", Constants.COMPANYID, mCode);
                break;
        }
    }
}
